'use strict';
/*
  模型一定要写在app.model下
  表明一定要跟模型名称一致
*/

module.exports = app => {
  // 引入数据类型
  const { INTEGER, DATE, STRING, ENUM, TEXT } = app.Sequelize;
  // 配置
  const Report = app.model.define('report',{
    id: {type: INTEGER(20).UNSIGNED, primaryKey: true, autoIncrement: true},
    user_id: {type: INTEGER(20).UNSIGNED, allowNull: false, comment: '用户id',
      // 定义外键
      references: {
        model: 'user',  // 对应表名称
        key: 'id' // 对应表的主键
      },
      onUpdate: 'restrict', // 更新时操作
      onDelete: 'cascade' // 删除时操作
    },
    reported_id: { type: INTEGER(20).UNSIGNED, allowNull:false, comment: '被举报人id' },
    reported_type: { type: ENUM, 
      // 个人，群主
      values: ['user', 'group'], 
      allowNull: false, 
      comment: '举报类型' 
    },
    content: { type: TEXT, allowNull: true, defaultValue: '', comment: '举报内容' },
    category: { type:STRING(10), allowNull: true, defaultValue: '', comment: '举报分类' },
    status: { type: ENUM, values:['pending','refuse', 'agree'], allowNull: false, defaultValue: 'pending', comment: '举报状态' },
    created_at: DATE,
    updated_at: DATE
  });
  return Report
};